package com.zhengping.zpys.security.user;

import com.zhengping.zpys.security.user.role.UserRoleMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author chenweizuan
 * @description This is description of class
 * @version 1.0
 * @date 2020/3/28 13:51
 */
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Autowired
    private UserRoleMapper userRoleMapper;

    @Override
    public List<User> queryList(User user) {
        return userMapper.queryList(user);
    }

    @Override
    public Integer deleteList(Long[] usersId) {
        userMapper.deleteList(usersId);

        return userRoleMapper.deleteUserRole(usersId);
    }

    @Override
    public Integer creatUser(User user) {
        if (userMapper.isExist(user.getUserName())>0){
            return 0;
        }
        userMapper.creatUser(user);
        return userRoleMapper.creatUserRole(user.getUserId(),user.getRole().getRoleId());
    }

    @Override
    public Integer updateUser(User user) {
        userMapper.updateUser(user);
        return userRoleMapper.updateUserRole(user.getUserId(),user.getRole().getRoleId());
    }

    @Override
    public User queryUser(Long userId) {
        return userMapper.queryUser(userId);
    }

    @Override
    public User loginUser(String userName, String password) {
        return userMapper.loginUser(userName, password);
    }

    @Override
    public Integer isExist(String userName) {
        return userMapper.isExist(userName);
    }
}
